<template>
    <view>
        <!-- #ifdef MP-WEIXIN -->
        <view>
            <view class='header'>
                <image src='/static/images/logo.jpg'></image>
            </view>
            <view class='content'>
                <view>申请获取以下权限</view>
                <text>获得你的公开信息(昵称，头像、地区等)</text>
            </view>
            <button class='big-btn'  open-type="getUserInfo" withCredentials="true" lang="zh_CN"
                @getuserinfo="mpGetUserInfo">
                授权登录
            </button>
        </view>
        <!-- #endif -->
    </view>
</template>
<script>

    import httpPath from '@/static/js/path.js';
    export default {
        data() {
            return {
                popenid:''
            };
        },
        onLoad(option) {
            this.popenid = option.popenid || ''
            console.log(this.popenid)
        },
        methods: {
            mpGetUserInfo(result) {
                let that = this
                uni.showLoading()
				wx.login({
				  success (res) {
				    if (res.code) {
						 uni.request({
							url: httpPath.filePath+'/index/login/getOpenid',
							method:'POST',
							header:{'content-type':'application/x-www-form-urlencoded'},
							data: {code:res.code},
							success: (res) => {
								let userinfo = {}
								userinfo = result.detail.userInfo;
                                userinfo.openid = res.data.data.openid;
								// 请求接口入库信息
								uni.request({
									url: httpPath.filePath+'/index/login/getInfo',
									method:'POST',
									header:{'content-type':'application/x-www-form-urlencoded'},
									data: userinfo,
									success: (res) => {
										if(res.data.code==200){
										   if(res.data.data!=null){
											   uni.setStorage({
											       key: 'user',
											       data:res.data.data,
											       success: function () {
											          uni.hideLoading()
													  uni.navigateBack()
											       }
											   });
										   }
											
										}
										
									}
												
								});
							}
						 });
				    } else {
				      console.log('登录失败！' + res.errMsg)
				    }
				  }
				})
            },
        }
    }
</script>

<style>
    .header {
        margin: 90rpx 0 90rpx 50rpx;
        border-bottom: 1px solid #ccc;
        text-align: center;
        width: 650rpx;
        height: 300rpx;
        line-height: 450rpx;
    }

    .header image {
        width: 200rpx;
        height: 200rpx;
    }

    .content {
        margin-left: 50rpx;
        margin-bottom: 90rpx;
    }

    .content text {
        display: block;
        color: #9d9d9d;
        margin-top: 40rpx;
    }

    .bottom {
        border-radius: 80rpx;
        margin: 70rpx 50rpx;
        font-size: 35rpx;
    }
</style>

